﻿var page = {
    index: 0,
    time: 0,
    LoadUITimer: 0,
    UI_Flag: false,
    UI_Flag2: false,

    musicPictArray: [
        { picture0: "a1.png", picture1: "a2.png", picture2: "a3.png", picture3: "a4.png" },
        { picture0: "a5.png", picture1: "a6.png", picture2: "a7.png", picture3: "a8.png" },
        { picture0: "a9.png", picture1: "a10.png", picture2: "a11.png", picture3: "a12.png" },
        { picture0: "a15.png", picture1: "a16.png", picture2: "a17.png", picture3: "a18.png" },
    ],

    WomanArray: [
        { picture0: "w1.png", picture1: "w2.png", picture2: "w3.png", picture3: "w4.png" },
        { picture0: "w5.png", picture1: "w6.png", picture2: "w7.png", picture3: "w8.png" },
        { picture0: "w9.png", picture1: "w10.png", picture2: "w11.png", picture3: "w12.png" },
        { picture0: "w15.png", picture1: "w16.png", picture2: "w17.png", picture3: "w18.png" },
    ],

    ManArray: [
        { picture0: "m1.png", picture1: "m2.png", picture2: "m3.png", picture3: "m4.png" },
        { picture0: "m5.png", picture1: "m6.png", picture2: "m7.png", picture3: "m8.png" },
        { picture0: "m9.png", picture1: "m10.png", picture2: "m11.png", picture3: "m12.png" },
        { picture0: "m15.png", picture1: "m16.png", picture2: "m17.png", picture3: "m18.png" },
    ],

    musicArray: [
        { src4: "/mnt/sd0/filesystem/Cold water.mp3" },
        { src4: "/mnt/sd0/filesystem/Holy.mp3" },
        { src4: "/mnt/sd0/filesystem/Home to Mama.mp3" },
        { src4: "/mnt/sd0/filesystem/Monster.mp3" },
    ],

    musicName: [
        { name4: "Cold water-Justin Bieber" },
        { name4: "Holy-Justin Bieber" },
        { name4: "Home to Mama-Justin Bieber" },
        { name4: "Monster-Justin Bieber" },
    ],

    /* 此方法在第一次显示窗体前发生 */
    onLoad: function (event) {
        var that = this;
        that.LoadUITimer = setInterval(function () {
            if (that.UI_Flag != 0) {                         //已经获取到数据
                clearInterval(that.LoadUITimer);
            } else {
                that.loadmusicList();
                //that.loadmanList();
                //that.loadwomanList();
            }
        }, 1 * 500)

        that.setData({ btn2: { norImg: "find_music_of.png" } });    //当前界面为发现音乐
        that.time = setInterval(function () {
            that.setData({ WheelImage1: { value: that.index++ } });
        }, 1 * 1700)
    },

    /***************music Item******************/
    loadmusicList: function () {
        var that = this;
        var musicList = new Array();
        for (var i = 0, len = this.musicPictArray.length; i < len; i++) {
            var musicItem = new Object();
            musicItem.button1 = { norImg: this.musicPictArray[i].picture0, downImg: this.musicPictArray[i].picture0 };
            musicItem.button2 = { norImg: this.musicPictArray[i].picture1, downImg: this.musicPictArray[i].picture1 };
            musicItem.button3 = { norImg: this.musicPictArray[i].picture2, downImg: this.musicPictArray[i].picture2 };
            musicItem.button4 = { norImg: this.musicPictArray[i].picture3, downImg: this.musicPictArray[i].picture3 };
            musicList.push(musicItem);
        }
        this.setData({
            musicList: {
                list: {
                    page: this,
                    items: [{
                        xml: "Panels/musicItem", items: musicList
                    }]
                }
            }
        })
        that.UI_Flag = true;
    },


    /***************music_man Item******************/
    loadmanList: function () {
        var that = this;
        var man_List = new Array();
        for (var i = 0, len = this.ManArray.length; i < len; i++) {
            var manItem = new Object();
            manItem.imagebox1 = { value: this.ManArray[i].picture0 };
            manItem.imagebox2 = { value: this.ManArray[i].picture1 };
            manItem.imagebox3 = { value: this.ManArray[i].picture2 };
            manItem.imagebox4 = { value: this.ManArray[i].picture3 };
            man_List.push(manItem);
        }
        this.setData({
            manList: {
                list: {
                    page: this,
                    items: [{
                        xml: "Panels/musicianList",
                        items: man_List
                    }]
                }
            }
        })
        that.UI_Flag2 = true;
    },

    /***************music_woman Item******************/
    loadwomanList: function () {
        var that = this;
        var woman_List = new Array();
        for (var i = 0, len = this.WomanArray.length; i < len; i++) {
            var womanItem = new Object();
            womanItem.imagebox1 = { value: this.WomanArray[i].picture0 };
            womanItem.imagebox2 = { value: this.WomanArray[i].picture1 };
            womanItem.imagebox3 = { value: this.WomanArray[i].picture2 };
            womanItem.imagebox4 = { value: this.WomanArray[i].picture3 };
            woman_List.push(womanItem);
        }
        this.setData({
            womanList: {
                list: {
                    page: this,
                    items: [{
                        xml: "Panels/musicianList",
                        items: woman_List
                    }]
                }
            }
        })
    },

    /***************music mycollcet item******************/
    load_collcetmusic: function (data) {
        this.nameList = new Array();    //存放音乐名数组
        var musicList = new Array();

        for (var i = 0, len = this.musicArray.length; i < len; i++) {
            var musicItem = new Object();
            musicItem.label1 = new Object();
            musicItem.label1.value = this.musicName[i].name1;
            this.nameList.push(this.musicName[i].name1);
            musicItem.label1.value = this.musicName[i].name2;
            this.nameList.push(this.musicName[i].name2);
            musicItem.label1.value = this.musicName[i].name3;
            this.nameList.push(this.musicName[i].name3);
            musicItem.label1.value = this.musicName[i].name4;
            this.nameList.push(this.musicName[i].name4);
            musicList.push(musicItem);
        }

        this.setData({
            mycollectList: {
                list: {
                    page: this,
                    items: [{
                        xml: "Panels/musicListItem",
                        items: musicList
                    }]
                }
            }
        })
    },

    //点击单个图标跳到mp3列表page中
    Btn_wy_music: function (event) {
        console.log(event.target.id);
        audio.stop();
        pm.navigateTo({ url: "wy_music/wy_music", value: event.target.id.substring(6) })
    },

    /* 此方法展示窗体后发生 */
    onResume: function (event) {

    },

    /* 当前页状态变化为显示时触发 */
    onShow: function (event) {

    },

    /* 当前页状态变化为隐藏时触发 */
    onHide: function (event) {

    },

    /* 此方法关闭窗体前发生 */
    onExit: function (event) {
        if (this.time != 0) {
            clearInterval(this.time);
        }
        if (this.time != 0) {
            clearInterval(that.LoadUITimer);
        }
    },

    onBtn: function (event) {
        switch (event.target.id) {
            case "left":
                this.setData({ WheelImage1: { value: this.index-- } });
                break;
            case "right":
                this.setData({ WheelImage1: { value: this.index++ } });
                break;
            case "btn1":
                pm.navigateBack();
                break;
            case "btn2":
                this.setData({ card1: 0 });
                this.setData({ btn2: { norImg: "find_music_of.png" } });
                this.setData({ btn3: { norImg: "musicer.png" } });
                this.setData({ btn4: { norImg: "my_music.png" } });
                break;
            case "btn3":
                this.setData({ card1: 1 });
                this.setData({ btn2: { norImg: "find_music.png" } });
                this.setData({ btn3: { norImg: "musicer_of.png" } });
                this.setData({ btn4: { norImg: "my_music.png" } });
                if (this.UI_Flag2 == false) {
                    this.loadmanList();         //加载歌手信息
                }
                break;
            case "btn4":
                this.setData({ card1: 2 });
                this.setData({ btn2: { norImg: "find_music.png" } });
                this.setData({ btn3: { norImg: "musicer.png" } });
                this.setData({ btn4: { norImg: "mymusic_of.png" } });
                this.load_collcetmusic();       //加载个人收藏界面
                break;
            default:
                break;
        }
    },

    card_change1: function (event) {
        if ("change" == event.type) {
            switch (event.detail.value) {
                case 0:
                    this.setData({ btn2: { norImg: "find_music_of.png" } });
                    this.setData({ btn3: { norImg: "musicer.png" } });
                    break;
                case 1:
                    this.setData({ btn2: { norImg: "find_music.png" } });
                    this.setData({ btn3: { norImg: "musicer_of.png" } });
                    if (this.UI_Flag2 == false) {
                        this.loadmanList();     //加载歌手信息
                    }
                    break;
                default:
                    break;
            }
        }
    },

    card_change2: function (event) {
        var that = this;
        if ("change" == event.type) {
            switch (event.detail.value) {
                case 0:         //男歌星列表
                    if (that.UI_Flag2 == false) {
                        this.loadmanList();
                    }
                    break;
                case 1:         //女歌星列表
                    this.loadwomanList();
                    break;
            }
        }
    },

    ShowManList: function () {

    },

    ShowWomanList: function () {

    },
};

Page(page);

page = 0;
